<template>
	<BasicDrawer v-bind="$attrs" @register="registerDrawer" width="90%" showFooter destroyOnClose title="编辑检测信息"
		:width="900" @ok="handleSubmit">
		<!-- 报名用户信息 -->
		<BasicForm @register="registerForm">


		</BasicForm>
	</BasicDrawer>
</template>

<script lang="ts" setup>
	import { ref, computed, unref, watchEffect, toRaw } from 'vue';
	import { useUserStoreWithOut } from '/@/store/modules/user';
	import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
	import { BasicForm, useForm } from '/@/components/Form/index';
	import { columns, searchFormSchema } from './BsTravelgroupMaintuortravellinerecordLittle.data';
	import { BasicTable, useTable, TableAction, BasicColumn } from '/@/components/Table/index';
	import { formSchemaSelf } from '../BsTravelgroupMaintuortravellinerecordLittle.data';
	import { saveOrUpdateSelf } from '../BsTravelgroupMaintuortravellinerecord.api';
	//import { formSchema, usersColumns, pdtsColumns, tieredPricingColumns, payPriceColumns, earlyBirdPriceColumns, alternativeColumns } from './index.data';
	import { render, formattingMin, formattingDay } from '/@/utils/common/renderUtils';
	import { useMessage } from '/@/hooks/web/useMessage';
	import { cloneDeep } from 'lodash-es';
	// import { editOrderSite } from './index.api';
	// Emits声明
	const emit = defineEmits(['register', 'submit', 'entryType']);
	const isUpdate = ref(true);
	const earlyBirdPrice = ref([] as Array<any>)
	const jounerys = ref([] as Array<any>)
	const isCopy = ref(true);

	const userInfo = computed(() => {
		const userStore = useUserStoreWithOut();
		return userStore.getUserInfo;
	});

	//表单配置
	const [registerForm, { setProps, resetFields, setFieldsValue, getFieldsValue, validate }] = useForm({
		//labelWidth: 150,
		schemas: formSchemaSelf,
		showActionButtonGroup: false,
		baseColProps: { span: 12 },
		labelWidth: 120
	});
	//表单赋值
	const [registerDrawer, { closeDrawer, setDrawerProps }] = useDrawerInner(async (data) => {
		//重置表单
		await resetFields();
		setDrawerProps({
			confirmLoading: false,
			showCancelBtn: !!data?.showFooter, showOkBtn: !!data?.showFooter,
			// canFullscreen: false
		});
		isUpdate.value = !!data?.isUpdate;
		isCopy.value = !!data?.isCopy;
		// 	//表单赋值
		await setFieldsValue({
			...data.record,
		});
		setProps({ disabled: !data?.showFooter })
		earlyBirdPrice.value = [{ activeprice: '', priceexpiretime: '', sortnum: '', enddate: '', startdate: '' }]
	});

	const { createMessage } = useMessage();

	//设置标题
	// const title = computed(() => (!unref(isUpdate) ? '编辑检测信息' : '编辑'));
	//表单提交事件
	async function handleSubmit(v) {
		try {
			//这里提交表单到上级页面处理
			let values = await validate();

			//上下架时间

			if (values.xjSelect == 1) {
				values.enddateStr = '2026-01-01 00:00:00';
			}
			if (values.sjSelect == 1) {
				values.startdateSj = getCurrentDateTime();
			}
			console.log('-----')
			console.log('-----')
			console.log(values)
			values.travelMarkDays = JSON.stringify(jounerys.value)
			console.log('-----')
			console.log('-----')
			await saveOrUpdateSelf(values, isUpdate.value,isCopy.value);

			earlyBirdPrice.value = [{ activeprice: '', priceexpiretime: '', sortnum: '', enddate: '', startdate: '' }]
			//这里直接提交
			closeDrawer();
			//刷新列表
			emit('success');
			setDrawerProps({ confirmLoading: true });
			//刷新列表
		} finally {
			setDrawerProps({ confirmLoading: false });
		}
	}
	function getCurrentDateTime() {
		var now = new Date();
		var year = now.getFullYear();
		var month = now.getMonth() + 1; // 月份是从0开始的，所以需要+1
		var day = now.getDate();
		var hours = now.getHours();
		var minutes = now.getMinutes();
		var seconds = now.getSeconds() //秒
		// 如果需要补零，可以使用以下代码
		month = month < 10 ? '0' + month : month;
		day = day < 10 ? '0' + day : day;
		hours = hours < 10 ? '0' + hours : hours;
		minutes = minutes < 10 ? '0' + minutes : minutes;

		return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
	}


	const currentEditKeyRef = ref('');
</script>

<style lang="less" scoped>
	/** 时间和数字输入框样式 */
	:deep(.ant-input-number) {
		width: 100%
	}

	:deep(.ant-calendar-picker) {
		width: 100%
	}

	.margin-l-th {
		margin-left: 10px;
	}

	.colorRed {
		color: red;
	}

	.title {
		font-weight: 500;
	}

	h3 {
		font-weight: 700;
	}
</style>